home *** CD-ROM | disk | FTP | other *** search
- Path: news.mathworks.com!gatech!psinntp!psinntp!psinntp!pipeline!not-for-mail
- From: gniemcew@nyc.pipeline.com (Gabriel Niemcewicz)
- Newsgroups: comp.lang.c++
- Subject: newbie help with 2-d arrays please ?
- Date: 16 Apr 1996 04:21:27 -0400
- Organization: Pipeline
- Message-ID: <4kvla7$516@pipe9.nyc.pipeline.com>
- X-PipeUser: gniemcew
- X-PipeHub: nyc.pipeline.com
- X-PipeGCOS: (Gary)
- X-Newsreader: Pipeline v3.5.0
-
- Hi !
-
- I am currently writing a project on graphs and I encountered something I
- cannot figure out when writing adjacency matrix representation:
-
- class graph {
-
- int size; // number of vertices in a representation
- int *array; // ptr to the allocated 2-d array
-
- <snip>
- };
-
- And the following doesn't work:
-
- int
- graph::add_vertex(int vertex_id)
- {
- int* table;
- table = new int [temp_size][temp_size]; // this gives me errors about
- static declaration type required....?
-
- <snip>
- table[i][j] = -1;
-
- <snip>
-
- table[i][j] = array[i][j];
-
- <snip>
-
- array=table; // ini header value
-
- <snip>
-
- array[vertex1-1][vertex2-1] = weight; // store adjacency info
- array[vertex2-1][vertex1-1] = weight; // update both links
- }
-
- <snip>
-
- printf ("%3d", array[i][j]);
-
- I can't reference the array at all. I read two books on c++, but only 1-D
- arrays are discussed.
- I bet the reason is some tricky pointer declaration, something like int*
- array[][], or something like that.
- I need to allocate arrays dynamically because I am doing rehashing on them
- as new vertices are addded.
-
- Any suggestions ? I would appreciate some feedback.
-
- Please mail me at gniemcew@shiva.hunter.cuny.edu
-
- Thx,
-
- Gary
-